package com.cbdp.common.dto;

import com.github.pagehelper.Page;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * com.cbdp.common.dto
 *
 * @author 白雨浓
 * date: 2018/10/26 12:01
 * content: Page 结果 传递模型
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PageDTO<T> {

    private int current;

    private int size;

    private long total;

    private List<T> list;

    public static <T> PageDTO<T> newInstance(Page<T> page) {
        return new PageDTO<>(page);
    }

    private PageDTO(Page<T> page) {
        this.current = page.getPageNum();
        this.size = page.getPageSize();
        this.total = page.getTotal();
        this.list = page;
    }
}
